package com.neteast.androidclient.contact.util;

import com.neteast.androidclient.contact.R;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.widget.RemoteViews;

public class NotificationHelper {
	
	private Context mContext;
	private NotificationManager mNotifyManager;
	private int NOTIFICATION_ID = 0x00011003;
	private Notification notify;
	
	public NotificationHelper(Context mContext) {
		this.mContext = mContext;
		mNotifyManager=(NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
	}
	
	public void createNotification(String text){
		notify = new Notification();
		notify.icon=R.drawable.ic_launcher;
		notify.contentView=new RemoteViews(mContext.getPackageName(), R.layout.layout_notify);
		notify.contentView.setTextViewText(R.id.text, text);
		notify.contentView.setProgressBar(R.id.progress, 100, 0, false);
		notify.contentView.setImageViewResource(R.id.ico, R.drawable.ic_launcher);
		notify.flags=Notification.FLAG_ONGOING_EVENT;
		mNotifyManager.notify(NOTIFICATION_ID, notify);
	}
	
	public void progressUpdate(int newProgress) {
		notify.contentView.setProgressBar(R.id.progress, 100, newProgress, false);
		mNotifyManager.notify(NOTIFICATION_ID, notify);
		if (100==newProgress) {
			mNotifyManager.cancel(NOTIFICATION_ID);
		}
	}
	
	public void completed() {
		mNotifyManager.cancel(NOTIFICATION_ID);
	}
}
